/*
 * @Description: 
 * @Author: 赵升华
 * @Date: 2019-09-02 09:15:06
 * @LastEditors: 赵升华
 * @LastEditTime: 2019-09-02 09:15:06
 */
import Vue from 'vue'
import Router from 'vue-router'
import Index from '@/components/pages/index/Index'
import Helper from '@/components/pages/helper/Helper'
import Login from '@/components/pages/login/Login'
import Register from '@/components/pages/register/Register'
import Forget from '@/components/pages/forget/Forget'
import Invest from '@/components/pages/invest/Invest'
import Invest_pt from '@/components/pages/invest_pt/Invest'
import PlatformDetail from '@/components/pages/platformDetail/PlatformDetail'
import ProductDetail from '@/components/pages/productDetail/ProductDetail'
import Debt from '@/components/pages/debt/Debt'
import ReleasePage from '@/components/pages/release/Release'


import SearchPage from '@/components/pages/search/SearchPage'
import DebtSearchPage from '@/components/pages/search/DebtSearchPage'
import My from '@/components/pages/my/My'
import GetMoneyBack from '@/components/pages/getMoneyBack/GetMoneyBack'
import InvestRecord from '@/components/pages/investRecord/InvestRecord'
import TransactionDetail from '@/components/pages/transactionDetail/TransactionDetail'
import CashManager from '@/components/pages/cashManager/CashManager'
import BindAlipay from '@/components/pages/bindAlipay/BindAlipay'
import BindBank from '@/components/pages/bindBank/BindBank'
import ChangeBank from '@/components/pages/changeBank/ChangeBank'
import ChangeAlipay from '@/components/pages/changeAlipay/ChangeAlipay'
import BackPlan from '@/components/pages/backPlan/BackPlan'
import Service from '@/components/pages/service/Service'
import SetPage from '@/components/pages/set/Set'
import SetPwd from '@/components/pages/setPwd/SetPwd'
import SetPhone from '@/components/pages/setPhone/SetPhone'
import SetPhoneStep2 from '@/components/pages/setPhone/SetPhoneStep2'
import SetPhoneStep3 from '@/components/pages/setPhone/SetPhoneStep3'
import Message from '@/components/pages/message/Message'
import MsgDetail from '@/components/pages/msgDetail/MsgDetail'
import Share from '@/components/pages/share/Share'
import Guide from '@/components/pages/guide/Guide'
import Question from '@/components/pages/question/Question'
import ShareDetail from '@/components/pages/shareDetail/ShareDetail'
import ErrorPage from '@/components/pages/error/Error'
import Buy from '@/components/pages/buy/Buy'
import NewsDetail from '@/components/pages/newsDetail/NewsDetail'
import Agreement from '@/components/pages/agreement/Agreement'

import RegisterActivity from '@/components/pages/activity/Register'
import ShareActivity from '@/components/pages/activity/ShareActivity'
import WorldCup from '@/components/pages/activity/WorldCup'
import QActivity from '@/components/pages/activity/QActivity'
import Lucky2018_1 from '@/components/pages/activity/Lucky2018_1'
import Lucky2018_2 from '@/components/pages/activity/Lucky2018_2'
import Updata20 from '@/components/pages/activity/Updata'
import Insurance from '@/components/pages/activity/insurance'


Vue.use(Router)

import {getStore,setStore,getQueryString,getQS,getLStore} from '../config/mUtils'

const router = new Router({
  scrollBehavior (to, from, savedPosition) {
    if (savedPosition) {
      return savedPosition
    } else {
      if (from.meta.keepAlive) {
        from.meta.savedPosition = document.body.scrollTop;
      }
        return { x: 0, y: to.meta.savedPosition || 0 }
    }
  },
  mode:'history',
  routes: [
    // {
    //   path: '/',
    //   name: 'Home',
    //   redirect:'home',
    //   component: Index,
    // },
    {
      path: '/',
      // redirect:'home',
      name: 'Index',
      component: Index,
      meta: { keepAlive: true }
    },
    {
      path: '/buy',
      name: 'Buy',
      component: Buy,
    },
    {
      path: '/home',
      name: 'Index',
      component: Index,
      // meta: { keepAlive: true }
    },
    {
      path: '/helper',
      name: 'Helper',
      component: Helper,
      meta:{
        keepAlive:true
      }
    },
    {
      path: '/login',
      name: 'Login',
      component: Login,
      meta:{
        keepAlive:true
      }
    },
    {
      path: '/register',
      name: 'Register',
      component: Register,
      meta:{
        keepAlive:true
      }
    },
    {
      path: '/forget',
      name: 'Forget',
      component: Forget,
      meta:{
        keepAlive:true
      }
    },
    {
      path: '/invest',
      name: 'Invest',
      component: Invest,
      meta: { keepAlive: true }
    },
    {
      path: '/invespt',
      name: 'Invest_pt',
      component: Invest_pt,
      meta: { keepAlive: true }
    },
    {
      path: '/newsDetail/:id',
      name: 'news_detail',
      component: NewsDetail,
    },
    {
      path: '/platformDetail',
      name: 'PlatformDetail',
      component: PlatformDetail
    },
    {
      path: '/productDetail',
      name: 'ProductDetail',
      component: ProductDetail,
    },
    {
      path: '/search',
      name: 'SearchPage',
      component: SearchPage
    },
    {
      path: '/debtSearch',
      name: 'DebtSearchPage',
      component: DebtSearchPage
    },
    {
      path: '/my',
      name: 'My',
      component: My
    },
    {
      path: '/getMoneyBack',
      name: 'GetMoneyBack',
      component: GetMoneyBack
    },
    {
      path: '/agreement',
      name: 'Agreement',
      component: Agreement,
      meta: { keepAlive: true }
    },
    {
      path: '/investRecord',
      name: 'InvestRecord',
      component: InvestRecord
    },
    {
      path: '/transactionDetail',
      name: 'TransactionDetail',
      component: TransactionDetail
    },
    {
      path: '/backPlan',
      name: 'BackPlan',
      component: BackPlan
    },
    {
      path: '/cashManager',
      name: 'CashManager',
      component: CashManager,
    },
    {
      path: '/cashManager/BindBank',
      name: 'BindBank',
      component: BindBank,
    },
    {
      path: '/cashManager/bindAlipay',
      name: 'BindAlipay',
      component: BindAlipay,
    },
    {
      path: '/cashManager/changeBank',
      name: 'ChangeBank',
      component: ChangeBank,
    },
    {
      path: '/cashManager/changeAlipay',
      name: 'ChangeAlipay',
      component: ChangeAlipay,
    },
    {
      path: '/service',
      name: 'Service',
      component: Service,
    },
    {
      path: '/message',
      name: 'Message',
      component: Message,
    },
    {
      path: '/setPage',
      name: 'SetPage',
      component: SetPage,
    },
    {
      path: '/set/setPwd',
      name: 'SetPwd',
      component: SetPwd,
    },
    {
      path: '/set/setPhone',
      name: 'SetPhone',
      component: SetPhone,
    },
    {
      path: '/set/setPhoneStep2',
      name: 'SetPhoneStep2',
      component: SetPhoneStep2,
    },
    {
      path: '/set/setPhoneStep3',
      name: 'SetPhoneStep3',
      component: SetPhoneStep3,
    },
    {
      path: '/message/msgDetail',
      name: 'MsgDetail',
      component: MsgDetail,
    },
    {
      path: '/share',
      name: 'Share',
      component: Share,
    },
    {
      path: '/guide',
      name: 'Guide',
      component: Guide,
    },
    {
      path: '/question',
      name: 'Question',
      component: Question,
    },
    {
      path: '/shareDetail',
      name: 'ShareDetail',
      component: ShareDetail,
    },
    {
      path: '/debt',
      name: 'Debt',
      component: Debt,
      meta: { keepAlive: true }
    },
    {
      path: '/release',
      name: 'Release',
      component: ReleasePage,
      meta: { keepAlive: true }
    },
    {
      path: '/registerActivity',
      name: 'RegisterActivity',
      component: RegisterActivity,
    },
    {
      path: '/shareActivity',
      name: 'ShareActivity',
      component: ShareActivity,
    },
    {
      path: '/worldCup',
      name: 'WorldCup',
      component: WorldCup,
    },
    {
      path: '/worldCup',
      name: 'WorldCup',
      component: WorldCup,
    },
    {
      path: '/QActivity',
      name: 'QActivity',
      component: QActivity,
    },
    {
      path: '/lucky2018',
      name: 'Lucky2018_2',
      component: Lucky2018_2,
    },
    {
      path: '/zhuanzhuan',
      name: 'Lucky2018_1',
      component: Lucky2018_1,
    },
    {
      path: '/updata20',
      name: 'Updata20',
      component: Updata20,
    },
    {
      path: '/insurance',
      name: 'Insurance',
      component: Insurance,
    },
    // {
    //   path: '/error',
    //   name: 'Error',
    //   component: ErrorPage,
    // },
    // {
    //   path: "*",
    //   redirect: "/error"
    // }
    {
      path: "*",
      component: ErrorPage
    }
  ]
})

router.beforeEach((to, from, next) => {
  
  //未登录的情况打开‘邀请返利’页面，跳转到登录页面
  if(to.name == 'Share'){
    if(!getStore('loginkey')){
      router.replace('/login')
      setStore('pre','/share')
    }
  }
  next()
})

router.afterEach(((to,from,next)=>{
  // console.log(from);
  if(from.name){
    setStore('pre',from.path)
  }
  setTimeout(()=>{
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?0d9f421b7cd5876d8d6e4281b787c505";
      var s = document.getElementsByTagName("script")[0]; 
      s.parentNode.insertBefore(hm, s);
    })();
  })
}),0)

export default router;